package org.ch00.test01.entity;

import java.util.Arrays;

/**
 * @author CSY
 * @date 2025 - 02 - 28
 */
public class CellPhone {
    /**
     * 品牌
     */
    private String brand;

    /**
     * 价格
     */
    private double price;

    /**
     * 名称
     */
    private String name;

    /**
     * 联系人列表
     */
    private String[] contactsList;

    public CellPhone(){}

    public CellPhone(String brand, double price, String name, String[] contactsList) {
        this.brand = brand;
        this.price = price;
        this.name = name;
        this.contactsList = contactsList;
    }

    public void internet(){
        System.out.println("上网...");
    }

    public void sendText(String name,String text){
        boolean flag = false;
        for (String c : this.contactsList ){
            if(name!=null && c.equals(name)){
                flag = true;
                break;
            }
        }
        if(flag){
            System.out.println("给" + name + "发送短信，内容为："+text);
        }else{
            System.out.println("给匿名用户发送信息，内容为："+text);
        }
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String[] getContactsList() {
        return contactsList;
    }

    public void setContactsList(String[] contactsList) {
        if (contactsList.length > 10){
            System.out.println("超出存储数量（10），自动保存前10名联系人！");
            this.contactsList = Arrays.stream(contactsList).limit(10).toArray(String[]::new);
        }else {
            this.contactsList = contactsList;
        }

    }
}
